package com.mmlc.meimei.lichengkongjian.classify;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.utils.XUtils;

import org.xutils.image.ImageOptions;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * Created by OutSide on 2017/1/1.
 */

public class ImageFragment extends Fragment {


    private static final String IMAGE_URL = "image";
    PhotoView image;
    private String imageUrl;
    PhotoViewAttacher mAttacher;
    public ImageFragment() {
        // Required empty public constructor
    }

    public static ImageFragment newInstance(String param1) {
        ImageFragment fragment = new ImageFragment();
        Bundle args = new Bundle();
        args.putString(IMAGE_URL, param1);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            imageUrl = getArguments().getString(IMAGE_URL);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_image, container, false);
        image = (PhotoView) view.findViewById(R.id.image);
        int width = getActivity().getWindowManager().getDefaultDisplay().getWidth();
        int height =(int) (getActivity().getWindowManager().getDefaultDisplay().getHeight()*0.6);
        ImageOptions.Builder buidler = new ImageOptions.Builder().setSize(width, height);
        buidler.setImageScaleType(ImageView.ScaleType.CENTER_INSIDE);
        XUtils.image(image,imageUrl, buidler.build());
//        Glide.with(getActivity()).load(imageUrl).into(image);
        mAttacher = new PhotoViewAttacher(image);

        mAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {

            @Override
            public void onPhotoTap(View arg0, float arg1, float arg2) {
                getActivity().finish();
            }
        });
        return view;
    }


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}
